

function adminProfileCtrl($scope, $route, $rootScope, $timeout, commonService , $location,$http) {
    
    $rootScope.adminLoginPage = false;
    
    _log('Admin adminProfileCtrl ###');
    
//    $scope.fieldData = $rootScope.pageData.user;
    $scope.fieldData = {};
    
//    var param = $location.search();
    var url = 'user_ws.php';
    var userid  = $rootScope.pageData.user.id;
    _log($rootScope.pageData.user.id);
    var params = {
       wsname : 'getuserbyid',
       id : userid,
       token : _pageData.tokenKey
    };
    $.getJSON(_COMMON.context + url, params).done(function(result) {
	$scope.$apply(function() {
	    $scope.fieldData = result.users;
	});
    });


    $scope.save = function () {

        var data = $scope.fieldData;
        _log('Edit !!!');
        
        if ($('#newpassword').val().trim() != $('#confirmnewpassword').val().trim()) {
            notif({
                msg: "<b><i class='fa fa-thumbs-o-down'></i> Confirm Password is not match !</b>",
                type: "error",
                position: "center"
            });

            $('#confirmnewpassword').focus();
            $('#confirmnewpassword').addClass('ng-invalid');
            return false;
        }
        
        var config = {
            params: {
                wsname: 'updateuser',
                token: _pageData.tokenKey,
                id: userid,
                username: data.username ? data.username : '',
                password: $('#newpassword').val(),
                displayname: data.displayname ? data.displayname : '',
                email: data.email ? data.email : '',
                firstname: data.firstname ? data.firstname : '',
                lastname: data.lastname ? data.lastname : '',
                age: data.age ? data.age : '',
                birthday: $('#birthday').val(),
                usertype: data.usertype,
                status: 1 
            }
        };

//        _log(config);
        $http.post(_COMMON.context + url, null, config)
	      .success(function (obj) {
	          notif({
	              msg: "<b><i class='fa fa-thumbs-o-up'></i>  Save Success !</b>",
	              type: "success",
	              position: "center"
	          });
	          $location.path('/admin/profile/'); 
	      })
          .error(function () {
              alert('Error is occured, May be database connect is wrong');
          });
    };
    
    $(".datepicker").datepicker({
    	dateFormat : 'dd/mm/yy',
//    	showOn : "button",
    	buttonImage : "app/images/calendar_blue.png",
//    	buttonImageOnly : false,
    	beforeShow: function(){    
    	           $(".ui-datepicker").css('font-size', 13) ;
    	    }
    });
    
    
}
